<?php

namespace Modules\Web\Http\Controllers;


use Illuminate\Http\Request;
use Modules\Web\Service\GoodsService;

class GoodsController extends BaseController
{
    /**
     * 商品分类列表
     * yang 20191029
     */
    public function get_goods_cate()
    {
        $arr_list = GoodsService::get_goods_cate();
        return response_json($arr_list);
    }

    /**
     * 获取商品规格分类列表
     * 2019 11 07
     */
    public function get_specs_cate_list(){
        $arr_list = GoodsService::get_specs_cate_list();
        return response_json($arr_list);
    }

    /**
     *  商品列表
     *  yang 20191029
     *
     */
    public function get_goods_list(Request $request)
    {
        $arrInput = $request->all();
        $arr_list = GoodsService::get_goods_list((array)$arrInput);
        return response_json($arr_list);
    }

    /**
     *    获取该门店的所有商品
     *    yang 20191029
     **/
    public function get_goods_all(Request $request)
    {
        $arrInput = $request->all();
        $arr_list = GoodsService::get_goods_all((array)$arrInput);

        return response_json($arr_list);
    }

    /**
     *    获取指定商品详情
     *    yang 20191029
     *
     **/
    public function get_goods_info(Request $request)
    {
        $nId = $request->get('id');
        $arr_list = GoodsService::get_goods_info((int)$nId);
        return response_json($arr_list);
    }

    /**
     * 添加商品
     * yang 2019 10 29
     */
    public function add_goods(Request $request)
    {
        $data = $request->all();

        $goods_data = json_decode($data['goods_data'],true);

        shiwu_start();
        $arr_list = GoodsService::add_goods((array)$goods_data);
        shiwu_end($arr_list);

        return response_json($arr_list);
    }

    /**
     * 编辑商品
     * yang 2019 10 30
     */
    public function edit_goods(Request $request)
    {
        $data = $request->all();
        $goods_data = json_decode($data['goods_data'],true);

        shiwu_start();
        $arr_list = GoodsService::edit_goods((array)$goods_data);
        shiwu_end($arr_list);

        return response_json($arr_list);
    }

    /**
     * 删除商品规格属性
     * 2019 11 07
     */
    public function del_goods_product(Request $request){
        $gid = $request->get('id');
        $arr_list = GoodsService::del_goods_product((int)$gid);
        return response_json($arr_list);
    }

    /**
     * 商品上下架
     * yang 2019 10 30
     */
    public function change_goods_status(Request $request)
    {
        $data = $request->all();
        $arr_list = GoodsService::change_status((array)$data);
        return response_json($arr_list);
    }

    /**
     * 删除商品
     * yang 2019 10 30
     */
    public function del_goods(Request $request)
    {
        $data = $request->all();
        $arr_list = GoodsService::del_goods((array)$data);
        return response_json($arr_list);
    }



    /*****************************************服务商品**************************************************/

    /**
     * 商品分类列表
     * yang 2019 10 30
     */
    public function get_repair_type()
    {
        $arr_list = GoodsService::get_repair_type();
        return response_json($arr_list);
    }

    /**
     * 服务商品列表
     * yang 2019 10 30
     */
    public function get_repair_list(Request $request)
    {
        $arrInput = $request->all();
        $arr_list = GoodsService::get_repair_list((array)$arrInput);

        return response_json($arr_list);
    }

    /**
     * 添加服务商品
     * yang 2019 10 31
     */
    public function add_repair_goods(Request $request)
    {
        $data = $request->all();

        shiwu_start();
        $arr_list = GoodsService::add_repair_goods((array)$data);
        shiwu_end($arr_list);

        return response_json($arr_list);
    }

    /**
     * 编辑服务商品
     * yang 2019 10 31
     */
    public function edit_repair_goods(Request $request)
    {
        $data = $request->all();

        shiwu_start();
        $arr_list = GoodsService::edit_repair_goods((array)$data);
        shiwu_end($arr_list);

        return response_json($arr_list);
    }

    /**
     * 获取服务商品详情
     * yang 2019 10 31
     */
    public function get_repair_goods_info(Request $request)
    {
        $nId = $request->get('id');
        $arr_list = GoodsService::get_repair_goods_info((int)$nId);
        return response_json($arr_list);
    }

    /**
     * 服务商品上下架
     * yang 2019 10 31
     */
    public function change_repair_status(Request $request)
    {
        $data = $request->all();
        $arr_list = GoodsService::change_repair_status((array)$data);
        return response_json($arr_list);
    }

    /**
     * 删除服务商品
     * yang 2019 10 31
     */
    public function del_repair_goods(Request $request)
    {
        $data = $request->all();
        $arr_list = GoodsService::del_repair_goods((array)$data);
        return response_json($arr_list);
    }


    /**
     *  获取指定商品的评论信息
     *  hinq 2020 4 15
     *
     **/
    public function users_apprise_detail( Request $request ){
        $arr_input = (array) $request->all();
        return GoodsService::users_apprise_detail( (array) $arr_input );

    }


}